package com.hxkcloud.patient.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.hxkcloud.patient.R;
import com.hxkcloud.patient.viewholders.NoticeTimeSelectViewholder;

import java.util.ArrayList;

/**
 * Created by william_sun on 2016-07-12.
 * Description:新建用户执行单时间选择
 */
public class NoticeTimeSelectAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private ArrayList<String> times;
    private LayoutInflater mInflater;
    private NoticeTimeListener listener;

    public NoticeTimeSelectAdapter(Context mContext, ArrayList<String> datas,
                                   NoticeTimeListener listener) {
        this.mContext = mContext;
        this.times = datas;
        this.listener = listener;
        mInflater = LayoutInflater.from(mContext);
    }

    public void setData(ArrayList<String> datas) {
        this.times = datas;
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.adapter_noticetimeselect, null);
        NoticeTimeSelectViewholder holder = new NoticeTimeSelectViewholder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        NoticeTimeSelectViewholder mHolder = (NoticeTimeSelectViewholder) holder;
        mHolder.tv_time.setText(times.get(position));
        mHolder.iv_del.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onDelete(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return times.size();
    }

    public interface NoticeTimeListener {
        //删除
        void onDelete(int position);
    }
}
